<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>

</html>
<script src="./src/Crowdinto/index.js"></script>
<script>
    class Nodes {
        constructor(data) {
            data ? this.data = data : ""
            this.next=null
        }
    }
    class ListNodes {
        hnode = null
        lnode = null
        length = 0
        append(data) {
            let node = new Nodes(data)
            this.lnode ? this.lnode.next = node : ''
            this.hnode ? '' : this.hnode = node
            this.lnode = node
            this.lnode.next = this.hnode
            this.length++

        }
        insert(index, data) {
            if (index > this.length) {
                return
            }
            if(index===this.length){
                this.append(data)
                return
            }
            let node = new Nodes(data)
            this.length++
            if (index === 0) {
                ndoe.next = this.hnode
                this.hnode = node
                this.lnode.next = this.hnode
                return
            }

            let currentNode = this.hnode
            let idx = 0

            while (idx < index) {
                currentNode = idx === 0 ? this.hnode : currentNode.next
                idx++

            }
            // currentNode.next = node
            node.next=currentNode.next
            currentNode.next=node
        }

        edit(index, data) {
            let currentNode = this.hnode
            let idx = 0
            while (idx <= index) {
                currentNode = idx === 0 ? this.hnode : currentNode.next
                idx++
            }
            currentNode.data=data
        }
        delete(index, data) {
            if(index>=this.length){
                return
            }
            this.length--
            if(index===0){
                this.hnode=this.hnode.next
                this.lnode.next=this.hnode
                return
            }
            let currentNode = this.hnode
            let idx = 0
            while (idx < index) {
                currentNode = idx === 0 ? this.hnode : currentNode.next
                idx++
            }
            currentNode.next=currentNode.next.next
        }
        zebra() {
            // 判断长度是奇数还是偶数
            if (this.length % 2) {
               console.log("2",+Math.ceil(this.length/2));
               console.log("1",+Math.floor(this.length/2));
            } else {
                   console.log('11'+Math.max.apply(Math, array));
                   console.log('11'+this.length/2);
            }
        }
    }
    let list = new ListNodes
    list.append(1)

    list.append(2)
    list.append(3)
    list.append(4)
    list.delete(3)
    list.zebra()
    list.insert(2,520)

    console.log(list);



</script>